package com.china08.yxyapi.rabbitmq.listener;

import java.net.UnknownHostException;

import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.china08.yxyapi.config.RabbitConfig;
import com.china08.yxyapi.service.mg.impl.ExamBaseAnalyseServiceImpl;
import com.china08.yxyapi.service.mg.impl.ExamQuesAnalyseServiceImpl;
import com.mathworks.toolbox.javabuilder.MWException;

@Component
@EnableRabbit
public class ExamReportListener {

    @Autowired
    private ExamBaseAnalyseServiceImpl examBaseAnalyseServiceImpl;

    @Autowired
    private ExamQuesAnalyseServiceImpl examQuesAnalyseServiceImpl;

    // 进行接收并开始成绩分析
    @RabbitListener(queues = RabbitConfig.ClASS_EXAM_REPORT)
    public void examReport(String examId) throws MWException, UnknownHostException {
        // String hostname = (InetAddress.getLocalHost()).getHostName();
        // if (!"sbb-PC".equalsIgnoreCase(hostname)) { return; }
        examBaseAnalyseServiceImpl.saveExamBaseAnalyse(examId);
    }

    // 考试小题数据分析
    @RabbitListener(queues = RabbitConfig.ClASS_EXAMQUES_REPORT)
    public void examQuesReport(String examId) throws MWException, UnknownHostException {
        examQuesAnalyseServiceImpl.saveExamQuesOverviewAnalys(examId);
    }
}
